/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * <p>Project: jse2302 - Writer
 * <p>Powered by webrx On 2023-06-30 14:41:20
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Writer implements Runnable {
    private Socket socket = null;
    private String name = "客户";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Writer(Socket socket) {
        this.socket = socket;
    }

    public Writer(Socket socket, String name) {
        this.socket = socket;
        this.name = name;
    }

    public Writer() {
    }

    @Override
    public void run() {
        try {
            PrintWriter out = new PrintWriter(this.socket.getOutputStream());
            Scanner sc = new Scanner(System.in);
            while (true) {
                //发送s.getOutputStream();
                System.out.println("请输入信息：");
                String msg = "[" + this.name + "]:"+sc.nextLine() + "\r\n";
                out.write(msg);
                out.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
